<?php
/**
 *
 * @author yupoxiong<i@yupoxiong.com>
 */

declare (strict_types=1);

namespace app\admin\traits;

use support\Response;

trait AdminUpdateDataTrait
{

    public function updateData($data, $validate): Response
    {
        $param = (request())->all();

        $check = $validate->scene('admin_edit')->check($param);
        if (!$check) {
            return admin_error($validate->getError());
        }

        $result = $data->save($param);

        return $result ? admin_success('修改成功', [], URL_BACK) : admin_error('修改失败');
    }
}